﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace scomA3proj
{
    public sealed class HttpRequestWrapper
    {
        /// <summary>
        /// Gets the HTTP response from a web page. Headers are used based on the useHeaders flag.
        /// </summary>
        /// <param name="url">URI formatted URL(example:"http://www.yahoo.com").</param>
        /// <returns>Returns Html source of requested page.</returns>
        public static string getResponse(string url)
        {
            string result = "";
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                StreamReader reader = new StreamReader(response.GetResponseStream());
                result = reader.ReadToEnd();
            }
            catch (Exception ex)
            {
                result = "error";
            }
            return result;
        }
    }
}
